﻿using ApiDoc.DAL; 
using ApiDoc.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ApiDoc.Admin.Server.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class ParamController : ControllerBase
    {
        private readonly ParamDAL paramDAL; 

        public ParamController(ParamDAL paramDAL )
        {
            this.paramDAL = paramDAL; 
        }
 
        #region 参数

        [HttpGet("List")]
        public List<ParamModel> List(int FKSN)
        {
            List<ParamModel> list = this.paramDAL.Query(FKSN);
            return list;
        }

        [HttpPost("Save")]
        public int ParamSave(ParamModel model)
        {
            int result = 0;
            if (model.SN > 0)
            {
                result = this.paramDAL.Update(model);
            }
            else
            {
                result = this.paramDAL.Insert(model);
            }

            return result;
        }

        [HttpPost("Delete")]
        public int ParamDelete(List<int> ids)
        {
            int result = 0;

            foreach (int SN in ids)
            {
                ParamModel model = new ParamModel();
                model.SN = SN;
                int i = this.paramDAL.Delete(model);

                result += i;
            }

            return result;
        }


        //[HttpGet]
        ////获取测试参数
        //public IActionResult GetCSParam(int SN)
        //{
        //    List<ParamModel> paramList = this.paramDAL.Query(SN);
        //    return PartialView("/Views/Interface/_PartialCSParam.cshtml", paramList);
        //}


        #endregion



    }
}
